package tech.aistar.controller;

import tech.aistar.entity.Color;
import tech.aistar.entity.Phone;
import tech.aistar.entity.PhoneDetail;
import tech.aistar.entity.Size;
import tech.aistar.service.IColorService;
import tech.aistar.service.IPhoneDetailService;
import tech.aistar.service.IPhoneService;
import tech.aistar.service.ISizeService;
import tech.aistar.service.impl.ColorServiceImpl;
import tech.aistar.service.impl.PhoneDetailServiceImpl;
import tech.aistar.service.impl.PhoneServiceImpl;
import tech.aistar.service.impl.SizeServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @Author: lya
 * @Description: 本类的作用描述:
 * @CreateDate: 2019/9/8
 * @Version: 1.0
 */
@WebServlet("/phone/detail")
public class PhoneDetailAction extends HttpServlet{
    private IPhoneDetailService phoneDetailService = new PhoneDetailServiceImpl();
    private IColorService colorService = new ColorServiceImpl();
    private ISizeService sizeService = new SizeServiceImpl();
    private IPhoneService phoneService = new PhoneServiceImpl();
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        String phone_id = req.getParameter("phone_id");
        String phone_id = req.getParameter("id");
//        System.out.println(Integer.valueOf(phone_id));

        Phone phone = phoneService.findById(Integer.valueOf(phone_id));
        System.out.println(phone);
        req.getSession().setAttribute("phone",phone);


        PhoneDetail phoneDetail = phoneDetailService.findById(Integer.valueOf(phone_id));
        req.getSession().setAttribute("phoneDetail", phoneDetail);

        List<Color> colorList = colorService.findAll();
        req.getSession().setAttribute("colorList",colorList);

        List<Size> sizeList = sizeService.findAll();
        req.getSession().setAttribute("sizeList",sizeList);

        resp.sendRedirect(req.getContextPath() + "/nav/phone/detailView");

    }
}
